<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
	</body>


	<script>
		const person = {
			name: "张三",
			age: 15,
			language: ["java", "python", "css"]
		}


		console.log(Object.keys(person)); //["name", "age", "language"]
		console.log(Object.values(person)); //["jack", 21, Array(3)]
		console.log(Object.entries(person)); //[Array(2), Array(2), Array(2)]


		const target = {
			a: 1
		}
		const source1 = {
			b: 2
		}
		const source2 = {
			c: 3
		}
		Object.assign(target, source1, source2);
		console.log(target); //{a: 1, b: 2, c: 3}

		// 2. 声明对象简写
		const age = 23;
		const name = "张三"
		const person1 = {
			age,
			name
		}; //声明对象简写
		console.log(person1);


		// 对象的函数属性简写
		let person3 = {
			name: "张三",
			age: 25,
			// 以前
			eat: function(food) {

				console.log(this.name + "再吃" + food);
			},

			//现在使用箭头函数, 箭头函数中 this不能使用, 对象.属性

			eat2: food => console.log(person3.name + "在吃" + food),
			eat3(food) {
				console.log(person3.name + "再吃" + food);
			}
		}
		person3.eat("苹果");
		person3.eat2("香蕉");
		person3.eat3("橘子");

		// 对象扩展运算符

		//(1) 拷贝对象(深拷贝)
		let p1 = {
			name: "张三",
			age: 13
		}
		let someone = { ...p1
		};
		console.log(someone); // {name: "张三", age: 13}


		//(2)合并对象
		let age1 = {
			age: 16
		};
		let name1 = {
			name: "zhangsan"
		}
		let p2 = {
			name: "张三"
		}
		p2 = { ...age1,
			...name1
		};
		console.log(p2); // {age: 16, name: "zhangsan"}
	</script>
</html>
